<{extend name="Public:public0" /}>

<{block name="title"}>变量名 及 命名规范<{/block}>

<{block name="sidebar"}><{include file="Public:sidebar-Es6" /}><{/block}>

<{block name="content"}>
<div class="content guide with-sidebar components-guide">
<h1>变量名 及 命名规范</h1>	
<h2 id="变量名">
	<a href="#变量名" class="headerlink" title="变量名" data-scroll="">变量名</a>
</h2>
<ol>
	<li>必须以 <code>字母</code>  <code>"_"</code> 或者 <code>"$"</code> 为开头</li>
	<li>首个字不能为 <code>数字</code>, 中间不允许使用 空格</li>
	<li>严格区分大小写 (javascript就是 区分大小写的)</li>
	<li>不可使用 关键字 和 保留字</li>
	<li>长度不能超过255个字符</li>
</ol>
<p>example</p>
<code class="prettyprint linenums prettyprinted" style=""><ol class="linenums"><li class="L0"><span class="com">//&nbsp;以字母或下划线_或$开头</span></li><li class="L1"><span class="pun">合法：</span><span class="pln">oa</span><span class="pun">、</span><span class="pln">ob</span><span class="pun">、</span><span class="pln">AA</span><span class="pun">、</span><span class="pln">$aaa</span><span class="pun">、</span><span class="pln">_fag</span></li><li class="L2"><span class="pun">不合法：</span><span class="pln">oa</span><span class="pun">*</span><span class="pln">b</span><span class="pun">、</span><span class="pln">h</span><span class="pun">&amp;</span><span class="pln">b</span><span class="pun">、</span><span class="pln">hh</span><span class="com">#jj</span></li><li class="L3"><span class="com">//&nbsp;长度不超过255字符</span></li><li class="L4"><span class="pun">合法：</span><span class="pln">oa</span><span class="pun">、</span><span class="pln">oaaaaaaaaaa</span><span class="pun">、</span><span class="pln">o</span><span class="pun">.........</span><span class="pln">aaaaaaa</span><span class="pun">(......为省略，但是总长不超过</span><span class="lit">255</span><span class="pun">字符)</span></li><li class="L5"><span class="pun">不合法：</span><span class="pln">o</span><span class="pun">.........</span><span class="pln">aaaaaaa</span><span class="pun">(......为省略，但是总长超过</span><span class="lit">255</span><span class="pun">字符)</span></li><li class="L6"><span class="com">//&nbsp;不能使用空格</span></li><li class="L7"><span class="pun">合法：</span><span class="pln">oa</span><span class="pun">、</span><span class="pln">o_a</span><span class="pun">、</span><span class="pln">o_A</span></li><li class="L8"><span class="pun">不合法：</span><span class="pln">o&nbsp;a</span><span class="pun">、</span><span class="pln">oa&nbsp;a</span><span class="pun">、</span><span class="pln">oA_h&nbsp;h&nbsp;b</span></li><li class="L9"><span class="com">//&nbsp;不能使用关键字及保留字</span></li><li class="L0"><span class="pun">不合法：</span><span class="kwd">class</span><span class="pun">、</span><span class="pln">style</span><span class="pun">、</span><span class="pln">html</span></li><li class="L1"><span class="com">//&nbsp;区分大小写</span></li><li class="L2"><span class="pln">oBtn</span><span class="pun">与</span><span class="pln">obtn</span><span class="pun">不同、</span><span class="pln">oa</span><span class="pun">与</span><span class="pln">oA</span><span class="pun">不同</span></li></ol></code>

<br><br><br>

<h2 id="命名规范">
	<a href="#命名规范" class="headerlink" title="命名规范" data-scroll="">命名规范</a>
</h2>
<h4>1、匈牙利命名法：类型前缀+首字母大写</h4>
<code class="prettyprint linenums prettyprinted" style=""><ol class="linenums"><li class="L0"><span class="kwd">var</span><span class="pln">&nbsp;sUserName&nbsp;</span><span class="pun">=</span><span class="pln">&nbsp;</span><span class="str">'css8'</span><span class="pun">;</span></li><li class="L1"><span class="kwd">var</span><span class="pln">&nbsp;iCount&nbsp;</span><span class="pun">=</span><span class="pln">&nbsp;</span><span class="lit">0</span><span class="pun">;</span></li></ol></code>
<table>
	<tr>
		<th>变量类型</th>
		<th>变量前缀</th>
	</tr>
	<tr>
		<td>String 字符串</td>
		<td>s</td>
	</tr>
	<tr>
		<td>Array数组</td>
		<td>a</td>
	</tr>
	<tr>
		<td>Float浮点数</td>
		<td>l</td>
	</tr>
	<tr>
		<td>Funciton函数</td>
		<td>f</td>
	</tr>
	<tr>
		<td>Integer(int)整型</td>
		<td>n</td>
	</tr>
	<tr>
		<td>Object对象</td>
		<td>a</td>
	</tr>
	<tr>
		<td>Regular Expression正则</td>
		<td>r</td>
	</tr>
</table>
<br>


<h4>2、骆驼式/驼峰命名法</h4>
第一个单词首字母 <code>小写</code>
<code class="prettyprint linenums prettyprinted" style=""><ol class="linenums"><li class="L0"><span class="kwd">var</span><span class="pln">&nbsp;printLoadTemplates</span><span class="pun">;</span><span class="pln">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="com">//&nbsp;名称首字母小写，其他每个单词的首字母大写</span></li><li class="L1"><span class="kwd">var</span><span class="pln">&nbsp;print_load_templates</span><span class="pun">;</span><span class="pln">&nbsp;&nbsp;&nbsp;</span><span class="com">//&nbsp;下划线法，每个单词用一个下划线标记</span></li></ol></code>
<br>

<h4>3、帕斯卡命名法</h4>
和驼峰命名法类似，但是，而帕斯卡命名法第一个单词首字母也 <code>大写</code>
<code class="prettyprint linenums prettyprinted" style=""><ol class="linenums"><li class="L0"><span class="kwd">var</span><span class="pln">&nbsp;</span><span class="typ">PrintLoadTemplates</span><span class="pun">;</span><span class="pln"> </span><span class="com">// 第一个单词首字母也大写</span></li></ol></code>


</div>
<{/block}>
